package servlets;

import java.io.IOException;
import java.util.Vector;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.PositionService;
import entityJPA.Position;

/**
 * Servlet implementation class DirectorGeneralServlet
 */
@WebServlet("/DirectorGeneralServlet")
public class DirectorGeneralServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@EJB
	private PositionService ps;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public DirectorGeneralServlet() {
		super();
		// TODO Auto-generated constructor stub
	}
	HttpSession h;
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		h = request.getSession();
		doPost(request, response);
	}

	private void loadList(HttpServletRequest request,
			HttpServletResponse response) {
		Vector<Position> list = this.getPositions();
//		h = request.getSession();
		h.setAttribute("listaPozitii", list);

		try {
			response.sendRedirect("directorGeneralPage.jsp");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		loadList(request, response);

	}

	public Vector<Position> getPositions() {
		try {
			Vector<Position> pozitii = new Vector<Position>();
			// pozitii.addAll(ps.getActivePositions());
			pozitii.addAll(ps.getInactivePositions());
			return pozitii;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	
	

}
